﻿package javase.socket.net;

//Demonstrate URLConnection.
import java.net.*;
import java.io.*;
import java.util.Date;

public class URLConDemo {
	public static void main(String args[]) throws Exception {
		int c;
		URL hp = new URL("http://www.baidu.com");
		URLConnection hpCon = hp.openConnection();
		System.out.println("Date: " + new Date(hpCon.getDate()));
		System.out.println("Content-Type: " + hpCon.getContentType());
		System.out.println("Expires: " + hpCon.getExpiration());
		System.out.println("Last-Modified: "
				+ new Date(hpCon.getLastModified()));
		int len = hpCon.getContentLength();
		System.out.println("Content-Length: " + len);
		if (len > 0) {
			System.out.println("=== Content ===");
			InputStream input = hpCon.getInputStream();
			int i = len;
			while (((c = input.read()) != -1) && (--i > 0)) {
				System.out.print((char) c);
			}
			input.close();
		} else {
			System.out.println("No Content Available");
		}
	}
}

/*
Date: Wed Jun 20 10:16:09 CST 2007
Content-Type: text/html
Expires: 1182305769000
Last-Modified: Thu Jan 01 08:00:00 CST 1970
Content-Length: 3703
=== Content ===
<html><head><title>
*/